package com.zhudoo.zhilian.dao.impl;

import com.zhudoo.zhilian.dao.entity.City;
import com.zhudoo.zhilian.dao.entity.CityLine;
import com.zhudoo.zhilian.dao.entity.CityStation;
import com.zhudoo.zhilian.dao.repository.CityLineRepository;
import com.zhudoo.zhilian.dao.repository.CityRepository;
import com.zhudoo.zhilian.dao.repository.CityStationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CityDao {
    @Autowired
    CityRepository cityRepository;
    @Autowired
    CityLineRepository cityLineRepository;
    @Autowired
    CityStationRepository cityStationRepository;

    public List<City> getCityList() {
        return cityRepository.findAllByValid(true, Sort.by("enName").ascending());
    }

    public List<CityLine> getCityLineByCityId(int cityId) {
        return cityLineRepository.findByCityId(cityId, Sort.by("sort").ascending());
    }

    public List<CityStation> getCityStationBylineId(int line) {
        return cityStationRepository.findByLineId(line, Sort.by("sort").ascending());
    }

    public CityLine getCityLineById(int id) {
        return cityLineRepository.getOne(id);
    }

    public CityStation getStationLineById(int id) {
        return cityStationRepository.getOne(id);
    }
}
